package com.wt.demo;

import cn.hutool.core.lang.Assert;
import lombok.SneakyThrows;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("demo")
public class DemoController {
    @RequestMapping("ppt")
    @SneakyThrows
    public Result demo(MultipartFile file) {
        Assert.notNull(file, "文件不能为空");
        Assert.notBlank(file.getOriginalFilename(), "文件不能为空");
        SlideShow slideShow = null;
        if (file.getOriginalFilename().endsWith(".pptx")) {
            slideShow = new XMLSlideShow(file.getInputStream());
        }
        if (file.getOriginalFilename().endsWith(".ppt")) {
            slideShow = new HSLFSlideShow(file.getInputStream());
        }
        Assert.notNull(slideShow, "文件名错误");
        return PPTUtils.getContent(slideShow);
    }
}
